home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / FILTER.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  65 lines

  1. ############################################################################
  2. #
  3. #    File:     filter.icn
  4. #
  5. #    Subject:  Program skeleton for generic filter
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     December 5, 1989
  10. #
  11. ###########################################################################
  12. #
  13. #  Generic filter skeleton in Icon.
  14. #
  15. #  This program is not intended to be used as is -- it serves as a
  16. #  starting point for creation of filter programs.  Command line
  17. #  options, file names, and tabbing are handled by the skeleton.  You
  18. #  need only provide the filtering code.
  19. #
  20. #  As it stands, filter.icn simply copies the input file(s) to
  21. #  standard output.
  22. #
  23. #  Multiple files can be specified as arguments, and will be processed
  24. #  in sequence.  A file name of "-" represents the standard input file.
  25. #  If there are no arguments, standard input is processed.
  26. #
  27. ############################################################################
  28. #
  29. #  Links: options
  30. #
  31. ############################################################################
  32.  
  33. link options
  34.  
  35. procedure main(arg)
  36.    local opt, tabs, Detab, fn, f, line
  37.    #
  38.    #  Process command line options and file names.
  39.    #
  40.    opt := options(arg,"t+")      # e.g. "fs:i+r." (flag, string, integer, real)
  41.    if *arg = 0 then arg := ["-"] # if no arguments, standard input
  42.    tabs := (\opt["t"] | 8) + 1   # tabs default to 8
  43.    Detab := tabs = 1 | detab     # if -t 0, no detabbing
  44.    #
  45.    #  Loop to process files.
  46.    #
  47.    every fn := !arg do {
  48.       f := if fn == "-" then &input else
  49.         open(fn) | stop("Can't open input file \"",fn,"\"")
  50.       #
  51.       #  Loop to process lines of file (in string scanning mode).
  52.       #
  53.       while line := Detab(read(f)) do line ? {
  54.      write(line)       # copy line to standard output
  55.      }
  56.       #
  57.       #  Close this file.
  58.       #
  59.       close(f)
  60.       }
  61.    #
  62.    #  End of program.
  63.    #
  64. end
  65.